package view.stage
{
	import control.manager.LayerManager;
	import control.manager.MapManager;
	import control.manager.RoleManager;
	
	import data.GameConst;
	import data.MapData;
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	
	import ghostcat.display.game.Display45Util;
	
	import view.item.PathTrack;
	import view.layer.GameLayer;
	import view.layer.MapLayer;
	import view.layer.RoleLayer;
	import view.ui.UILogin;
	import view.ui.UIMain;
	import view.ui.UIPopupLayer;
	import view.ui.UITaskTalk;

	public class StageGame extends StageBase
	{
		/**
		 * 游戏层，游戏中的元素层 
		 */		
		private var gameLayer :GameLayer;
		/**
		 * 游戏ui界面，小地图，头像，底部栏 
		 */		
		private var mainUI :UIMain;
		
		public function StageGame()
		{
			super();
		}
		
		public function set enabled(v :Boolean):void
		{
			if(v)
			{
				this.mouseEnabled = true;
				this.mouseChildren = true;
			}else
			{
				this.mouseEnabled = false;
				this.mouseChildren = false;
			}
		}
		
		override public function initGame():void
		{
			super.initGame();
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			//ui弹出层
			UIPopupLayer.I;
			
			//游戏层
			this.gameLayer = new GameLayer(null,null);
			this.addChild(gameLayer);
			LayerManager.instance.layerDict[GameLayer.NAME] = this.gameLayer;
			

			//主UI
			this.mainUI = new UIMain();
			addChild(mainUI);
			LayerManager.instance.layerDict[UIMain.NAME] = this.mainUI;
			this.refreshInterval = 30;
			GameConst.gameRefreshInterval = this.refreshInterval;
			
			//最后加UI弹出层
			this.addChild(UIPopupLayer.I);
			//设置人物数据显示
			RoleManager.instance.setRoleUIDisplay();
			
			PathTrack.I;
			this.addChild(PathTrack.I);
			PathTrack.I.x = stage.stageWidth/2;
			PathTrack.I.y = stage.stageHeight/2;
			PathTrack.I.hide();
			
		}

		override public function clickHandler(event:MouseEvent):void
		{
			this.gameLayer.clickHandler(event);
//			trace(event.target);
		}
		
		override public function refreshHandler(event:TimerEvent):void
		{
			if(this.gameLayer)
			{
				this.gameLayer.update();
			}
		}
		
		override public function resizeHandler(event:Event):void
		{
			if(this.gameLayer)
			{
				this.gameLayer.resize();
			}
			
			if(this.mainUI)
			{
				this.mainUI.resize();
			}
			
			if(UIPopupLayer.I)
			{
				UIPopupLayer.I.resize();
			}
			
			if(PathTrack.I)
			{
				PathTrack.I.resize();
			}
		}
		

		
		override public function mouseDownHandler(event:MouseEvent):void
		{
			this.gameLayer.mouseDownHandler(event);
//			this.gameLayer.startDrag();
		}
		
		override public function mouseUpHandler(event:MouseEvent):void
		{
			this.gameLayer.mouseUpHandler(event);
//			this.gameLayer.stopDrag();
		}
	}
}